using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
namespace DAL
{
    public class ArchiveBackgrounds : DAL.DataManager<ArchiveBackground>
    {
        private static ArchiveBackgrounds Instance = new ArchiveBackgrounds();
        static ArchiveBackgrounds() { }

        public override string TableName
        {
            get { return @"fstdt_bgcolors"; }
        }

        protected override void CopyToItem(DataRow Row, ArchiveBackground Item)
        {
            Item.YearMonth = Convert.ToString(Row["YearMonth"]);


            Item.Color = Convert.ToString(Row["Color"]);
        }

        protected override void CopyFromItem(DataManagerQuery query, ArchiveBackground Item)
        {
            query.AddParam("YearMonth", Item.YearMonth);

            query.AddParam("Color", Item.Color);
        }

        public static ArchiveBackground Item(Int64 id)
        {
            return Instance.GetItem(id);
        }

        public static List<ArchiveBackground> All()
        {
            return Instance.GetItems();
        }

        public static void Add(ArchiveBackground Item)
        {
            Instance.Insert(Item);
        }

        public static void Remove(ArchiveBackground Item)
        {
            Instance.Delete(Item);
        }

        public static void Save(ArchiveBackground Item)
        {
            Instance.Update(Item);
        }

        public static ArchiveBackground GetByDateTime(DateTime date)
        {
            DataManagerQuery query = new DataManagerQuery();
            query.AddParam("YearMonth", date.ToString("yyyy/MM"));
            List<ArchiveBackground> myBgs = Instance.GetItems(query);
            if (myBgs.Count > 0)
            {
                return myBgs[0];
            }
            else
            {
                return null;
            }
        }

        public static ArchiveBackground GetLatestBackground()
        {
            DataManagerQuery query = new DataManagerQuery();
            query.AddSort("ID", Sort.Desc);
            DataManagerPage<ArchiveBackground> myBgs = Instance.GetItemsByPage(query, 1, 1);
            if (myBgs.Items.Count > 0)
            {
                return myBgs.Items[0];
            }
            else
            {
                return null;
            }
        }
    }

    public class ArchiveBackground : DAL.DataManagerRow
    {
        private string _YearMonth;
        public string YearMonth
        {
            get
            {
                return _YearMonth;
            }
            set
            {
                _YearMonth = value;
            }
        }


        private string _Color;
        public string Color
        {
            get
            {
                return _Color;
            }
            set
            {
                _Color = value;
            }
        }
    }
}